package 面试真题;

import java.util.Scanner;

/**
 * @author 帅小伙
 * @date 2022/1/28
 * @description
 */
public class Demo04贝壳找房2022java秋招笔试题2第3题 {


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int T = scanner.nextInt();

        for (int i = 0; i < T; i++) {
            int n = scanner.nextInt();
            String s = scanner.next();
            int  r = 0, count = 0;
            for (int j = 0; j <s.length(); j++) {
                if(s.charAt(j)=='('){
                    r++;
                }else{
                    if(r == 0)count++;
                    else r--;
                }
            }
            System.out.println(count);
        }

    }

}
